package com.btl.service.ai.support.rag.store.vector.collections;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.qdrant.QdrantEmbeddingStore;
import io.qdrant.client.QdrantClient;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


public class VectorStoreQdrantFactory {

    private final QdrantClient qdrantClient;

    public VectorStoreQdrantFactory(QdrantClient qdrantClient) {
        this.qdrantClient = qdrantClient;
    }

    private final Map<String, EmbeddingStore<TextSegment>> storeCache = new ConcurrentHashMap<>();

    public EmbeddingStore<TextSegment> getQdrantClient(String collection) {
        return storeCache.computeIfAbsent(collection, c ->
                QdrantEmbeddingStore.builder()
                        .collectionName(c)
                        .client(qdrantClient)
                        .build()
        );
    }
}
